package com.yunxin.server.constant.enums;

import com.yunxin.common.result.IResultCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * @author zero°
 * @since 2023-06-21
 */
@Getter
@RequiredArgsConstructor
public enum GatewayResultCode implements IResultCode {

    /**
     * 系统执行出错
     */
    SYSTEM_EXECUTION_ERROR("B0001", "系统执行出错"),
    /**
     * 用户token为空
     */
    TOKEN_NULL_ERROR("GA000", "用户token为空"),
    /**
     * token校验失败
     */
    TOKEN_CHECK_ERROR("GA001", "token校验失败,请重新登录"),
    /**
     * 用户token已过期
     */
    TOKEN_VALIDATE_ERROR("GA002", "token校验异常,用户token已过期"),

    ;

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    private final String code;
    private final String msg;

    @Override
    public String toString() {
        return "{" +
                "\"code\":\"" + code + '\"' +
                ", \"msg\":\"" + msg + '\"' +
                '}';
    }


    public static GatewayResultCode getValue(String code) {
        for (GatewayResultCode value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        // 默认系统执行错误
        return SYSTEM_EXECUTION_ERROR;
    }

}
